<template>
  <div class="page" style="">
    <div class="print_title">保证金申请详情 · 禾美环保</div>
    <p class="title">基本信息</p>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px; position: relative;">
      <vue-qr class="codeImg" v-if="formData.bpmStatus == '3'" ref="qrCodeImg" :text="qrCodeText"></vue-qr>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">单据编号:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.billNo }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.proposer_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>

      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请部门:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.proposerDeptId_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请时间:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.createTime }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请公司:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{
              formData.applicant_dictText?formData.applicant_dictText:formData.applicant }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">单据类型:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.billCategory_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">费用类型:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.feeCategory_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">项目承接人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.projectUndertaker_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">保证金所属团队:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{
              formData.teamId_dictText?formData.teamId_dictText:formData.teamId }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col
        :span="12"
        v-if="formData.feeCategory == '2' || formData.feeCategory == '4' || formData.feeCategory == '5'">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">关联项目:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.preProjectId_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">项目编号:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.projectCode }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">业绩归属年度:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.attributionYear }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">关联投标档案:</p>
            <!-- <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.preProjectId_dictText?formData.preProjectId_dictText:formData.tenderId_dictText }}</p> -->
            <p style="margin:0 0 0 6px; word-break: break-all;">{{
              formData.tenderId_dictText?formData.preProjectId_dictText:'' }}</p>
          </a-col>
        </a-row>
      </a-col>
    </a-row>

    <p class="title" style="margin-top: 18px;">打款信息</p>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px;">
      <a-col :span="12" v-if="formData.feeCategory == '2'">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">是否投标转履约:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.isRelDeposit_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12" v-if="formData.feeCategory == '2' && formData.isRelDeposit == '1'">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">关联投标保证金:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.relDepositBill_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12" v-if="formData.feeCategory == '2' && formData.isRelDeposit == '1'">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">原投标保证金金额(元):</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.originPaymentAmount }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">汇款单位名称:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.remittanceUnit_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">汇款截止时间:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.remittanceEndTime }}</p>
          </a-col>
        </a-row>
      </a-col>

      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">汇款账户要求:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.remittanceAccountRequirements_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">汇款方式:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.remittanceMode_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col
        :span="12"
        v-if="formData.feeCategory == '3' || formData.feeCategory == '4' || formData.feeCategory == '5'">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">保函金额(元):</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.letterAmount }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">保证金金额(元):</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.remittanceAmount }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">本次支付金额(元):</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.currentPaymentAmount }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">收款单位名称:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.payeeUnit }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">收款方银联号:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.cnapsCode }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12" v-if="formData.remittanceMode=='2'">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">收款方开户行:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.payeeBankName }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12" v-if="formData.remittanceMode=='2'">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">收款方账户:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.payeeAccountNo }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12" v-if="formData.remittanceMode=='2'">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">收款联系人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.payeeContacts }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12" v-if="formData.remittanceMode=='2'">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">收款联系方式:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.payeeContactInfo }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">预计返款时间:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.estimateRefundTime }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="24">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">打款附言:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.postscript }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="24">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">情况说明:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.remark }}</p>
          </a-col>
        </a-row>
      </a-col>
    </a-row>

    <!-- <a-row type="flex" justify="center" v-if="dataSource && dataSource.length">
      <a-col>
        <p class="title_table">还款明细</p>
      </a-col>
      <a-col :span="24">
        <a-table
          :columns="columns"
          :data-source="dataSource"
          bordered
          :pagination="false"
          size="small"
          :rowClassName="tableRowClass"></a-table>
      </a-col>
    </a-row> -->

    <!-- 附件信息 -->
    <FileInfor :purchaseFile="purchaseFile" title="附件信息" v-if="purchaseFile && purchaseFile.length"></FileInfor>
    <!-- 流程详情 -->
    <ProcessInfor v-if="formData.bpmStatus !== '1'" :dataHistorySource="dataHistorySource"></ProcessInfor>
  </div>
</template>
<script>
import { getAction } from '@/api/manage'
import FileInfor from '@/components/print/FileInfor.vue' // 审批历史流程列表组件
import ProcessInfor from '@/components/print/ProcessInfor.vue' // 审批历史流程列表组件
import address from '@/components/AddressChoice/address.js'
import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
import VueQr from 'vue-qr'
export default {
	props: {
		formData: {
			type: Object,
			default: () => {},
			required: true
    },
		formDataHistory: {
			type: Object,
			default: () => {},
			required: true
    }
	},
  components: {
    FileInfor,
    ProcessInfor,
    VueQr
  },
  data() {
    return {
      qrCode: null,
      address,
      filterMultiDictText,
      dictOptions: {},
      dataSource: [], // 物料列表
      columns: [
      {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 45,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '关联借款单',
            align: 'center',
            width: 80,
            dataIndex: 'loanBillId',
            scopedSlots: { customRender: 'loanBillId' }
          },
          {
            title: '借款金额(元)',
            align: 'center',
            width: 65,
            dataIndex: 'amount'
          },
          {
            title: '使用日期',
            align: 'center',
            width: 65,
            dataIndex: 'useDate',
            customRender: function (text) {
              return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
            }
          },
          {
            title: '归还日期',
            align: 'center',
            width: 65,
            dataIndex: 'returnDate',
            customRender: function (text) {
              return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
            }
          },
          {
            title: '本次还款金额(元)',
            align: 'center',
            width: 65,
            dataIndex: 'currentReturnAmount'
          },
          {
            title: '累计已还金额(元)',
            align: 'center',
            width: 65,
            dataIndex: 'returnedTotalAmount'
          },
          {
            title: '累计已报销金额(元)',
            align: 'center',
            width: 75,
            dataIndex: 'reimbursedTotalAmount'
          },
          {
            title: '总冲账金额(元)',
            align: 'center',
            width: 65,
            dataIndex: 'totalAmount'
          },
          {
            title: '剩余未还金额(元)',
            align: 'center',
            width: 65,
            dataIndex: 'unreturnedTotalAmount'
          },
          {
            title: '备注',
            align: 'center',
            dataIndex: 'remark'
          }
			],
			dataHistorySource: [], // 流程列表
			url: {
				list: '/api/erp/finance/repayment/erpFinanceRepaymentSlipDetail/allList', // 物料明细列表
				historyList: '/api/erpmng/act/task/processHistoryList' // 流程历史跟踪接口
			},
			purchaseFile: [] // 附件
    };
  },
	watch: {
		formData: {
			async handler (val) {
				if (val) {
					this.list()
					this.getHistoryList()
          this.initDictConfig() // 字典值
					if (val.attachments) {
						this.purchaseFile = val.attachments.split(',')
					}
				}
			},
			immediate: true
		},
		formDataHistory: {
			handler (val) {
				if (val) {
					this.getHistoryList()
				}
			},
			immediate: true
		}
	},
  computed: {
    qrCodeText () {
      return JSON.stringify({
        billNo: this.formData.billNo,
        billType: '4'
      })
    }
  },
	methods: {
		// 获取列表
		getHistoryList() {
			var params = { processInstanceId: this.formDataHistory.procInsId };// 查询条件
			getAction(this.url.historyList, params).then(res => {
				if (res.success) {
					this.dataHistorySource = res.result.records || res.result
				}
			})
		},

    async initDictConfig() {
      initDictOptions('erp_finance_loan_bill,bill_no,id').then(async(res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'loanBillId', res.result)
        }
      })
    },

		list () {
			if (!this.formData.id) {
				return false
			}
			var params = {
        billId: this.formData.id
			}
			getAction(this.url.list, params).then(res => {
				if (res.success) {
						this.dataSource = res.result.records || res.result
						this.dataSource.forEach((item, index) => {
						item.key = index
					})
				}
      })
		},

		tableRowClass(record, index) {
			console.log('record, index', record, index)
			if (index == 0) {
				return 'rowClass';
			}
      return ''
    },

    getAddress (text) {
      if (!text) {
        return false
      }
      var areaList = text.split(',')
      var areaText = ''
      this.address.map(value => {
        if (areaList[0] && areaList[0] == value.code) {
          areaText = areaText + value.name + '/'
          if (value && value.children && value.children.length) {
            value.children.map(val => {
              if (areaList[1] && areaList[1] == val.code) {
                areaText = areaText + val.name + '/'

                if (val && val.children && val.children.length) {
                  val.children.map(va => {
                    if (areaList[2] && areaList[2] == va.code) {
                      areaText = areaText + va.name
                    }
                  })
                }
              }
            })
          }
        }
      })
      return areaText
    }
	}
};
</script>
<style lang="less" scoped>
.page{
	background: #ffffff;
	padding: 19px 28px 0 28px;
	width: 750px;
	.print_title{
		font-size: 15px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-bottom: 9px;
	}
	.title {
		background: #EEEEEE;
		font-size: 13px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
		padding: 11px 9px;
	}
	.title_table{
		font-size: 13px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
	}
}
/deep/ .rowClass{
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-thead th{
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-thead tr{
	background: #EEEEEE;
}
/deep/ .ant-table-small > .ant-table-content > .ant-table-body {
    margin: 0 0px;
}
/deep/ .ant-table-body tr {
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-body tr td {
    word-wrap:break-word;
    word-break:break-all;
  }
.content{
  font-size: 13px;
}
.codeImg{
  width: 56px;
  height: 56px;
  background: #ccc;
  position: absolute;
  right: 0px;
  top: 0px;
}
</style>
